use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "reservations")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    pub guest_name: String,
    pub guest_email: String,
    pub guest_phone: String,
    pub room_number: String,
    pub check_in_date: Date,
    pub check_out_date: Date,
    #[sea_orm(column_type = "Text")]
    pub status: String, // "PENDING", "PAID", "CHECKED_IN", "CHECKED_OUT", "CANCELLED"
    pub total_amount: f64,
    pub created_at: DateTime,
    pub updated_at: DateTime,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}

impl Model {
    pub fn to_status_str(status: crate::grpc::reservation::ReservationStatus) -> String {
        match status {
            crate::grpc::reservation::ReservationStatus::Pending => "PENDING".to_string(),
            crate::grpc::reservation::ReservationStatus::Paid => "PAID".to_string(),
            crate::grpc::reservation::ReservationStatus::CheckedIn => "CHECKED_IN".to_string(),
            crate::grpc::reservation::ReservationStatus::CheckedOut => "CHECKED_OUT".to_string(),
            crate::grpc::reservation::ReservationStatus::Cancelled => "CANCELLED".to_string(),
        }
    }

    pub fn from_status_str(status: &str) -> crate::grpc::reservation::ReservationStatus {
        match status {
            "PENDING" => crate::grpc::reservation::ReservationStatus::Pending,
            "PAID" => crate::grpc::reservation::ReservationStatus::Paid,
            "CHECKED_IN" => crate::grpc::reservation::ReservationStatus::CheckedIn,
            "CHECKED_OUT" => crate::grpc::reservation::ReservationStatus::CheckedOut,
            "CANCELLED" => crate::grpc::reservation::ReservationStatus::Cancelled,
            _ => crate::grpc::reservation::ReservationStatus::Pending,
        }
    }
}